package org.jeecg.modules.farming.mini.controller;

import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.api.client.util.ArrayMap;
import com.google.common.collect.Maps;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import net.sf.saxon.expr.Component;
import org.apache.commons.lang.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.constant.CacheConstant;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.system.api.ISysBaseAPI;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.system.util.JwtUtil;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.CommonUtils;
import org.jeecg.common.util.PasswordUtil;
import org.jeecg.common.util.RedisUtil;
import org.jeecg.common.util.chuanglan.ChuangLanSmsHelper;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.base.service.BaseCommonService;
import org.jeecg.modules.farming.faInfo.entity.FaInfo;
import org.jeecg.modules.farming.faInfo.service.IFaInfoService;
import org.jeecg.modules.farming.mini.MiniResult;
import org.jeecg.modules.farming.mini.WechatDecryptDataUtil;
import org.jeecg.modules.farming.news.entity.News;
import org.jeecg.modules.farming.news.entity.NewsComment;
import org.jeecg.modules.farming.news.entity.VisitUser;
import org.jeecg.modules.farming.news.service.INewsService;
import org.jeecg.modules.farming.product.entity.FaProduct;
import org.jeecg.modules.farming.product.entity.ProductComment;
import org.jeecg.modules.farming.product.service.IFaProductService;
import org.jeecg.modules.farming.product.service.IProductCommentService;
import org.jeecg.modules.farming.technology.entity.TecPraise;
import org.jeecg.modules.farming.technology.entity.TechnologyNews;
import org.jeecg.modules.farming.technology.service.ITechnologyNewsService;
import org.jeecg.modules.system.entity.SysCategory;
import org.jeecg.modules.system.entity.SysDictItem;
import org.jeecg.modules.system.entity.SysUser;
import org.jeecg.modules.system.service.ISysCategoryService;
import org.jeecg.modules.system.service.ISysDictItemService;
import org.jeecg.modules.system.service.ISysUserService;
import org.jeecg.modules.system.util.SecurityUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.FileCopyUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.logging.Logger;

/**
 * @Description: 小程序接口
 * @Author: Samiu
 * @Date:   2020-12-12
 * @Version: V1.0
 */
@Api(tags="小程序接口")
@RestController
@RequestMapping("/mini")
@Slf4j
public class MiniController {
    @Autowired
    private ISysCategoryService sysCategoryService;
    @Autowired
    private IFaInfoService faInfoService;
    @Autowired
    private ISysUserService sysUserService;
    @Autowired
    private RedisUtil redisUtil;
    @Autowired
    private ITechnologyNewsService technologyNewsService;
    @Autowired
    private INewsService newsService;
    @Autowired
    private IFaProductService faProductService;
    @Autowired
    private ISysBaseAPI sysBaseAPI;
    @Autowired
    private ISysDictItemService sysDictItemService;
    @Autowired
    private IProductCommentService productCommentService;

    @Resource
    private BaseCommonService baseCommonService;
    @Value("${wx.appId}")
    private String appId;
    @Value("${wx.appSecret}")
    private String appSecret;

    /**
     * 本地：local minio：minio 阿里：alioss
     */
    @Value(value="${jeecg.uploadType}")
    private String uploadType;
    @Value(value = "${jeecg.path.upload}")
    private String uploadpath;
    @Value("${wx.fullUrl}")
    private String fullUrl;
    /**
     * 会员分类
     * @return
     */
    @AutoLog(value = "会员分类")
    @ApiOperation(value="会员分类", notes="会员分类")
    @GetMapping(value = "/userCategory")
    public MiniResult<List<Map<String, Object>>> userCategory(@RequestParam(name="pid",required=true) String pid) throws Exception {
        MiniResult<List<Map<String, Object>>> result = new MiniResult<List<Map<String, Object>>>();

        QueryWrapper<SysCategory> queryWrapper = new QueryWrapper<SysCategory>();
        queryWrapper.eq("pid", pid);

        Page<SysCategory> page = new Page<SysCategory>(1, 100);
        IPage<SysCategory> pageList = sysCategoryService.page(page, queryWrapper);

        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        if (pageList.getSize() > 0) {
            for (int i = 0; i < pageList.getRecords().size(); i++) {
                SysCategory category = pageList.getRecords().get(i);

                Map<String, Object> map = new HashMap<String, Object>();
                IPage<SysCategory> jpageList = new Page<SysCategory>();
                if (category.getName().equals("加工")) {
                    QueryWrapper<SysCategory> qWrapper = new QueryWrapper<SysCategory>();
                    qWrapper.eq("pid", category.getId());

                    Page<SysCategory> jpage = new Page<SysCategory>(1, 100);
                    jpageList = sysCategoryService.page(jpage, qWrapper);
                }
                map.put("id", category.getId());
                map.put("name", category.getName());

                List<Map<String, Object>> childList = new ArrayList<Map<String, Object>>();
                if (jpageList.getSize() > 0)
                {
                    for (int j = 0; j < jpageList.getRecords().size(); j++) {
                        Map<String, Object> childMap = new HashMap<String, Object>();
                        childMap.put("id", jpageList.getRecords().get(j).getId());
                        childMap.put("name", jpageList.getRecords().get(j).getName());
                        childList.add(childMap);
                    }
                }
                map.put("childList", childList);
                list.add(map);
            }
        }
        result.setCount(list.size());
        result.setData(list);
        return result;
    }

    /**
     * 关于我们（联盟介绍、秘书处单位）
     * @return
     */
    @AutoLog(value = "关于我们（联盟介绍、秘书处单位）")
    @ApiOperation(value="关于我们（联盟介绍、秘书处单位）", notes="关于我们（联盟介绍、秘书处单位）")
    @GetMapping(value = "/aboutUsByType")
    public MiniResult<IPage<FaInfo>> aboutUsByType(@RequestParam(name="type",required=true) Integer type) throws Exception {
        MiniResult<IPage<FaInfo>> result = new MiniResult<IPage<FaInfo>>();

        QueryWrapper<FaInfo> queryWrapper = new QueryWrapper<FaInfo>();
        queryWrapper.eq("info_type", type);
        Page<FaInfo> page = new Page<FaInfo>(1, 10);
        IPage<FaInfo> pageList = faInfoService.page(page, queryWrapper);
        result.setCount(1);
        result.setData(pageList);
        return result;
    }


    /**
     * 查询指定联盟会员分类的用户
     * @return
     */
    @AutoLog(value = "查询指定联盟会员分类的用户")
    @ApiOperation(value="查询指定联盟会员分类的用户", notes="查询指定联盟会员分类的用户")
    @GetMapping(value = "/queryUsersByCategory")
    public MiniResult<List<Map<String, Object>>> queryUsersByCategory(
            @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
            @RequestParam(name="city",required=false) String city,
            @RequestParam(name="keyword",required=false) String keyword,
            @RequestParam(name="cateId",required=true) String cateId
    ) throws Exception {
        MiniResult<List<Map<String, Object>>> result = new MiniResult<List<Map<String, Object>>>();

        QueryWrapper<SysUser> queryWrapper = new QueryWrapper<SysUser>();
        queryWrapper.eq("org_id", cateId);
        if (city!=null && !city.equals("全部")){
            queryWrapper.like("city", city);
        }
        if(keyword!=null){
            queryWrapper.like("union_name", keyword);
        }

        Page<SysUser> page = new Page<SysUser>(pageNo, 10);
        IPage<SysUser> pageList = sysUserService.page(page, queryWrapper);
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        if (pageList.getSize() > 0) {
            for (int i = 0; i < pageList.getRecords().size(); i++) {
                SysUser user = pageList.getRecords().get(i);
                Map<String, Object> map = new HashMap<String, Object>();
                map.put("id", user.getId());
                String strUrl = SecurityUtil.GetFullUrl(user.getAvatar(),fullUrl);
                map.put("imgUrl", strUrl);
                map.put("unionName", user.getUnionName());
                map.put("label", user.getTitle());
                map.put("address", user.getAddress());

                list.add(map);
            }
        }
        result.setCount(list.size());
        result.setData(list);
        return result;
    }

    /**
     * 小程序 - 获取联盟用户状态
     * @return
     */
    @AutoLog(value = "小程序 - 获取联盟用户状态")
    @ApiOperation(value="小程序 - 获取联盟用户状态", notes="小程序 - 获取联盟用户状态")
    @GetMapping(value = "/getUnionStatus")
    public MiniResult<Map<String, Object>> getUnionStatus(@RequestParam(name="unionId",required=true) String unionId

    ) throws Exception {
        MiniResult<Map<String, Object>> result = new MiniResult<Map<String, Object>>();

        // 查询用户信息
        QueryWrapper<SysUser> queryWrapper = new QueryWrapper<SysUser>();
        queryWrapper.eq("id", unionId);
        SysUser user = sysUserService.getOne(queryWrapper);
        Map<String, Object> map = new ArrayMap<>();

        // 查询字典
        QueryWrapper<SysDictItem> queryDictItemWrapper = new QueryWrapper<SysDictItem>();
        queryDictItemWrapper.eq("dict_id","fc6cd58fde2e8481db10d3a1e68ce70c");//字典：用户状态
        queryDictItemWrapper.eq("item_value",oConvertUtils.getString(user.getStatus()));//字典项：用户状态值
        SysDictItem dict = sysDictItemService.getOne(queryDictItemWrapper);

        map.put("strStatus",dict.getItemText());
        map.put("status",user.getStatus());

        result.setCount(1);
        result.setData(map);
        return result;
    }

    /**
     * 联盟详情 -> 联盟用户信息
     * @return
     */
    @AutoLog(value = "联盟详情 -> 联盟用户信息")
    @ApiOperation(value="联盟详情 -> 联盟用户信息", notes="联盟详情 -> 联盟用户信息")
    @GetMapping(value = "/queryUserById")
    public MiniResult<List<Map<String, Object>>> queryUserById(@RequestParam(name="userId",required=false) String userId,
                                                    @RequestParam(name="selectedUnionId",required=false) String selectedUnionId

    ) throws Exception {
        MiniResult<List<Map<String, Object>>> result = new MiniResult<List<Map<String, Object>>>();

        QueryWrapper<SysUser> queryWrapper = new QueryWrapper<SysUser>();
        queryWrapper.eq("id", selectedUnionId);

        Page<SysUser> page = new Page<SysUser>(1, 10);
        IPage<SysUser> pageList = sysUserService.page(page, queryWrapper);

        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        if (pageList.getSize() > 0) {
            for (int i = 0; i < pageList.getRecords().size(); i++) {
                SysUser user = pageList.getRecords().get(i);
                Map<String, Object> map = new HashMap<String, Object>();
                map.put("id", user.getId());
                String logo = SecurityUtil.GetFullUrl(user.getAvatar(),fullUrl);
                map.put("logo", logo);
                map.put("linkMan", user.getRealname());
                map.put("unionName", user.getUnionName());
                map.put("linkWay", user.getPhone());
                map.put("cateId", user.getOrgId());

                // 查询联盟会员分类
                QueryWrapper<SysCategory> qWrapper = new QueryWrapper<SysCategory>();
                qWrapper.eq("id", user.getOrgId());
                SysCategory category = sysCategoryService.getOne(qWrapper);
                ArrayList cateIds = new ArrayList();
                // 一、二、三级分类
                String fatherIdL1 = "";
                String secondIdL2 = "";
                String thirdIdL3 = user.getOrgId();
                // 二级分类
                if (!category.getPid().equals("0")){
                    qWrapper = new QueryWrapper<SysCategory>();
                    qWrapper.eq("id", category.getPid());
                    category = sysCategoryService.getOne(qWrapper);
                    secondIdL2 = category.getId();
                    // 一级分类
                    if (!category.getPid().equals("0")){
                        qWrapper = new QueryWrapper<SysCategory>();
                        qWrapper.eq("id", category.getPid());
                        category = sysCategoryService.getOne(qWrapper);
                        fatherIdL1 = category.getId();
                    }
                }
                if (fatherIdL1!=""){
                    cateIds.add(fatherIdL1);
                }
                if (secondIdL2!=""){
                    cateIds.add(secondIdL2);
                }
                if (thirdIdL3!=""){
                    cateIds.add(thirdIdL3);
                }
                map.put("cateIds", cateIds);
                ArrayList busImg = new ArrayList();
                if (user.getLicense()!=null){
                    String busImgUrl = SecurityUtil.GetFullUrl(user.getLicense(),fullUrl);
                    busImg.add(busImgUrl);
                }
                map.put("busImg", busImg);              //营业执照
                ArrayList prodImg = new ArrayList();
                if (user.getIdCardOne()!=null){
                    String url = SecurityUtil.GetFullUrl(user.getIdCardOne(),fullUrl);
                    prodImg.add(url);
                }
                if (user.getIdCardTwo()!=null){
                    String url = SecurityUtil.GetFullUrl(user.getIdCardTwo(),fullUrl);
                    prodImg.add(url);
                }
                if (user.getIdCardThree()!=null){
                    String url = SecurityUtil.GetFullUrl(user.getIdCardThree(),fullUrl);
                    prodImg.add(url);
                }
                map.put("prodImg", prodImg);            //身份证
                ArrayList entrustImg = new ArrayList();
                if (user.getAuthUrl()!=null){
                    String url = SecurityUtil.GetFullUrl(user.getAuthUrl(),fullUrl);
                    entrustImg.add(url);
                }
                map.put("entrustImg", entrustImg);      //委托书
                map.put("email", user.getEmail());
                map.put("status", user.getStatus());
                String strStatus = "";
                if (user.getStatus() == 1){
                    strStatus = "正常";
                }
                map.put("strStatus", strStatus);
                map.put("label", user.getTitle());
                map.put("address", user.getAddress());
                map.put("lon", user.getLon());
                map.put("lat", user.getLat());
                map.put("details", user.getContent());
                list.add(map);
            }
        }
        result.setCount(list.size());
        result.setData(list);
        return result;
    }

    @ApiOperation("小程序授权--通过code拿到用户基础信息,并返回token、session_key")
    @RequestMapping(value = "/unionGetWxOpenId",method = RequestMethod.GET)
    @ResponseBody
    public Result<?> unionGetWxOpenId(@RequestParam("code") String code,@RequestParam("id") String id){
        return sysUserService.unionGetWxOpenId(code,id);
    }

    /**
     * 小程序登录
     * @return
     */
    @AutoLog(value = "小程序登录")
    @ApiOperation(value="小程序登录", notes="小程序登录")
    @GetMapping(value = "/login")
    public MiniResult<Map<String, Object>> login(@RequestParam(name="userName",required=true) String userName,
                                        @RequestParam(name="password",required=true) String password
    ) throws Exception {
        MiniResult<Map<String, Object>> result = new MiniResult<Map<String, Object>>();

        LambdaQueryWrapper<SysUser> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SysUser::getUsername,userName);
        SysUser user = sysUserService.getOne(queryWrapper);

        Result r = sysUserService.checkUserIsEffective(user);
        if(!r.isSuccess()) {
            result.setMsg(r.getMessage());
            result.error500(r.getMessage());
            return result;
        }

        // 校验用户名或密码是否正确
        String userpassword = PasswordUtil.encrypt(userName, password, user.getSalt());
        String syspassword = user.getPassword();
        if (!syspassword.equals(userpassword)) {
            result.error500("用户名或密码错误");
            return result;
        }

        // 生成token
        String token = JwtUtil.sign(userName, syspassword);
        // 设置token缓存有效时间
        redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token);
        redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME*2 / 1000);

        Map<String, Object> map = new HashMap<String, Object>();
        map.put("token", token);

        map.put("id", user.getId());
        map.put("logo", user.getAvatar());
        map.put("unionName", user.getUnionName());
        map.put("cateId", user.getOrgId());
        String url = SecurityUtil.GetFullUrl(user.getLicense(),fullUrl);
        map.put("url", user.getLicense());
        map.put("email", user.getOrgId());
        map.put("status", user.getStatus());
        String strStatus = "";
        if (user.getStatus() == 1){
            strStatus = "正常";
        }
        map.put("strStatus", strStatus);
        map.put("label", user.getTitle());
        map.put("address", user.getAddress());
        map.put("lon", user.getLon());
        map.put("lat", user.getLat());
        map.put("details", user.getContent());
        map.put("openId", user.getOpenId());
        result.setData(map);
        result.setMsg("登录成功");
        result.setCount(1);
        return result;
    }

    /**
     * 小程序-退出登录
     * @return
     */
    @AutoLog(value = "小程序-退出登录")
    @ApiOperation(value="小程序-退出登录", notes="小程序-退出登录")
    @PostMapping(value = "/logout")
    public MiniResult logout(@RequestBody JSONObject jsonObject) {
        //用户退出逻辑
        String token = jsonObject.getString("token");
        if(oConvertUtils.isEmpty(token)) {
            return MiniResult.error("退出登录失败！");
        }
        String username = JwtUtil.getUsername(token);
        LoginUser sysUser = sysBaseAPI.getUserByName(username);
        if(sysUser!=null) {
            //update-begin--Author:wangshuai  Date:20200714  for：登出日志没有记录人员
            baseCommonService.addLog("用户名: "+sysUser.getRealname()+",退出成功！", CommonConstant.LOG_TYPE_1, null,sysUser);
            //update-end--Author:wangshuai  Date:20200714  for：登出日志没有记录人员
            log.info(" 用户名:  "+sysUser.getRealname()+",退出成功！ ");
            //清空用户登录Token缓存
            redisUtil.del(CommonConstant.PREFIX_USER_TOKEN + token);
            //清空用户登录Shiro权限缓存
            redisUtil.del(CommonConstant.PREFIX_USER_SHIRO_CACHE + sysUser.getId());
            //清空用户的缓存信息（包括部门信息），例如sys:cache:user::<username>
            redisUtil.del(String.format("%s::%s", CacheConstant.SYS_USERS_CACHE, sysUser.getUsername()));
            //调用shiro的logout
            SecurityUtils.getSubject().logout();
            return MiniResult.ok("退出登录成功！");
        }else {
            return MiniResult.error("Token无效!");
        }
    }

    /**
     * 小程序-编辑联盟用户信息
     * @return
     */
    @AutoLog(value = "小程序-编辑联盟用户信息")
    @ApiOperation(value="小程序-编辑联盟用户信息", notes="小程序-编辑联盟用户信息")
    @PostMapping(value = "/editUser")
    public MiniResult<SysUser> editUser(@RequestBody JSONObject jsonObject) {
        MiniResult<SysUser> result = new MiniResult<SysUser>();
        try {
            SysUser sysUser = sysUserService.getById(jsonObject.getString("id"));
            if(sysUser==null) {
                result.error500("未找到对应实体");
            }else {
                SysUser user = JSON.parseObject(jsonObject.toJSONString(), SysUser.class);
                user.setAvatar(user.getAvatar());
                user.setAuthUrl(user.getAuthUrl());
                user.setIdCardOne(user.getIdCardOne());
                user.setIdCardTwo(user.getIdCardTwo());
                user.setIdCardThree(user.getIdCardThree());
                user.setLicense(user.getLicense());
                user.setUpdateTime(new Date());
                //String passwordEncode = PasswordUtil.encrypt(user.getUsername(), user.getPassword(), sysUser.getSalt());
                //抓取原来的数据
                user.setPassword(sysUser.getPassword());
                user.setSalt(sysUser.getSalt());
                user.setUsername(sysUser.getUsername());
                user.setStatus(sysUser.getStatus());
                user.setCreateBy(sysUser.getCreateBy());
                user.setCreateTime(sysUser.getCreateTime());
                user.setUpdateBy(sysUser.getUpdateBy());
                user.setUpdateTime(sysUser.getUpdateTime());
                user.setDepartIds(sysUser.getDepartIds());
                user.setOpenId(sysUser.getOpenId());
                if (user.getLon() == null){
                    user.setLon(sysUser.getLon());
                }
                if (user.getLat() == null){
                    user.setLat(sysUser.getLat());
                }
                sysUserService.updateById(user);
                result.setMsg("修改成功");
                result.setCount(1);
            }
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            result.error500("操作失败");
        }
        return result;
    }

    /**
     * 小程序-修改密码
     */
    @AutoLog(value = "小程序-修改密码")
    @ApiOperation(value="小程序-修改密码", notes="小程序-修改密码")
    @PostMapping(value = "/changePassword")
    public MiniResult changePassword(@RequestBody JSONObject jsonObject) {
        MiniResult result = new MiniResult();
        String uid = jsonObject.getString("unionId");
        String oldpassword = jsonObject.getString("oldPassword");
        String password = jsonObject.getString("newPassword");

        SysUser u = this.sysUserService.getOne(new LambdaQueryWrapper<SysUser>().eq(SysUser::getId, uid));
        if (u == null) {
            return MiniResult.error("用户不存在！");
        }
        String passwordEncode = PasswordUtil.encrypt(u.getUsername(), oldpassword, u.getSalt());
        if (!u.getPassword().equals(passwordEncode)) {
            return MiniResult.error("旧密码输入错误!");
        }

        SysUser sysUser = new SysUser();
        sysUser.setId(u.getId());
        String newPasswordEncode = PasswordUtil.encrypt(u.getUsername(), password, u.getSalt());
        sysUser.setPassword(newPasswordEncode);

        this.sysUserService.updateById(sysUser);

        result.setMsg("修改成功");
        result.setCount(1);
        return result;
    }

    /**
     * 小程序-注册
     * @return
     */
    @AutoLog(value = "小程序-注册")
    @ApiOperation(value="小程序-注册", notes="小程序-注册")
    @PostMapping(value = "/register")
    public MiniResult<SysUser> register(@RequestBody JSONObject jsonObject) {
        MiniResult<SysUser> result = new MiniResult<SysUser>();
        try {
            String userName = jsonObject.getString("userName");
            String password = jsonObject.getString("password");
            String unionName = jsonObject.getString("unionName");
            String cateId = jsonObject.getString("cateId");
            String address = jsonObject.getString("address");
            double lon = jsonObject.getDouble("lon");
            double lat = jsonObject.getDouble("lat");
            String email = jsonObject.getString("email");
            String label = jsonObject.getString("label");
            String linkMan = jsonObject.getString("linkMan");
            String logo = jsonObject.getString("logo");
            String busImg = jsonObject.getString("busImg");
            String idCardOne = jsonObject.getString("idCardOne");
            String idCardTwo = jsonObject.getString("idCardTwo");
            String idCardThree = jsonObject.getString("idCardThree");
            String entrustImg = jsonObject.getString("entrustImg");
            String linkWay = jsonObject.getString("linkWay");
            String details = jsonObject.getString("details");

            SysUser sysUser1 = sysUserService.getUserByName(userName);
            if (sysUser1 != null) {
                result.error500("用户名已注册");
                return result;
            }
            SysUser sysUser2 = sysUserService.getUserByPhone(linkWay);
            if (sysUser2 != null) {
                result.error500("该手机号已注册");
                return result;
            }
            if (oConvertUtils.isNotEmpty(email)) {
                SysUser sysUser3 = sysUserService.getUserByEmail(email);
                if (sysUser3 != null) {
                    result.error500("邮箱已被注册");
                    return result;
                }
            }

            SysUser user = new SysUser();
            user.setUsername(userName);
            user.setCreateTime(new Date());//设置创建时间
            String salt = oConvertUtils.randomGen(8);
            user.setSalt(salt);
            String passwordEncode = PasswordUtil.encrypt(userName, password, salt);
            user.setPassword(passwordEncode);
            user.setStatus(CommonConstant.USER_FREEZE);//注册后，状态【审核中】
            user.setDelFlag(CommonConstant.DEL_FLAG_0);
            user.setActivitiSync(CommonConstant.ACT_SYNC_0);
            user.setUnionName(unionName);
            user.setOrgId(cateId);
            user.setAddress(address);
            user.setLon(lon);
            user.setLat(lat);
            user.setEmail(email);
            user.setTitle(label);
            user.setRealname(linkMan);
            user.setAvatar(logo);
            user.setLicense(busImg);//营业执照
            user.setIdCardOne(idCardOne);
            user.setIdCardTwo(idCardTwo);
            user.setIdCardThree(idCardThree);
            user.setAuthUrl(entrustImg);//委托书
            user.setPhone(linkWay);
            user.setContent(details);
            user.setAvatar(user.getAvatar());
            user.setAuthUrl(user.getAuthUrl());
            user.setIdCardOne(user.getIdCardOne());
            user.setIdCardTwo(user.getIdCardTwo());
            user.setIdCardThree(user.getIdCardThree());
            user.setLicense(user.getLicense());
            //保存,且默认角色
            sysUserService.addUserWithRole(user, "1169504891467464705");//third_role 第三方登录角色

            // 发短信
            SysUser adminUser = sysUserService.getUserByName("001");//秘书处单位管理员账号
            if (adminUser != null && !StringUtils.isEmpty(adminUser.getPhone())) {
                String msg = ChuangLanSmsHelper.REGISTER_APPLY_TEMPLATE_CODE.replace("{$var}", userName);
                if (ChuangLanSmsHelper.sendMsg(msg, adminUser.getPhone())) {
                    log.info("注册发送短信成功！消息发送到：" + adminUser.getPhone() + "，内容为【" + msg + "】");
                } else {
                    log.info("注册发送短信失败！");
                }
            }

            result.setMsg("注册成功");
            result.setCount(1);

        } catch (Exception e) {
            log.error(e.getMessage(), e);
            result.error500("注册失败");
        }
        return result;
    }

    /**
     * 小程序-解析手机号
     * @return
     */
    @AutoLog(value = "小程序-解析手机号")
    @ApiOperation(value="小程序-解析手机号", notes="小程序-解析手机号")
    @PostMapping(value = "/decryptPhone")
    public MiniResult decryptPhone(@RequestBody JSONObject jsonObject) {
        MiniResult result = new MiniResult();
        try {
            String jsCode = jsonObject.getString("jsCode");
            Map params = new HashMap<>();
            params.put("appid",appId);
            params.put("secret", appSecret);
            params.put("js_code", jsCode);
            params.put("grant_type", "authorization_code");
            String ret = HttpUtil.get("https://api.weixin.qq.com/sns/jscode2session",params);
            Map<String, Object> temp = (Map) JSONUtil.parse(ret);
            String errCode = (String)temp.get("errcode");
            if (StringUtils.isBlank(errCode)){
                log.info("==== code2Session success ====");
//                String openid = (String)temp.get("openid");
                String session_key = (String)temp.get("session_key");

                String encryptedData = jsonObject.getString("encryptedData");
                String iv = jsonObject.getString("iv");
                String phone = WechatDecryptDataUtil.decryptData(encryptedData,session_key,iv);
                result.setMsg(phone);
                result.setCount(1);
                return result;
            }else {
                log.error("======【code2Session请求错误】=======errMsg:{}",temp.get("errmsg"));
                result.error500("code2Session请求错误");
            }
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            result.error500("操作失败");
        }
        return result;
    }

    /**
     * 文件上传统一方法
     * @param request
     * @param response
     * @return
     */
    @PostMapping(value = "/upload")
    public Result<?> upload(HttpServletRequest request, HttpServletResponse response) {
        Result<?> result = new Result<>();
        String savePath = "";
        String bizPath = request.getParameter("biz");
        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
        MultipartFile file = multipartRequest.getFile("file");// 获取上传文件对象
        if(oConvertUtils.isEmpty(bizPath)){
            if(CommonConstant.UPLOAD_TYPE_OSS.equals(uploadType)){
                //未指定目录，则用阿里云默认目录 upload
                bizPath = "upload";
                //result.setMessage("使用阿里云文件上传时，必须添加目录！");
                //result.setSuccess(false);
                //return result;
            }else{
                bizPath = "";
            }
        }
        if(CommonConstant.UPLOAD_TYPE_LOCAL.equals(uploadType)){
            //update-begin-author:lvdandan date:20200928 for:修改JEditor编辑器本地上传
            savePath = this.uploadLocal(file,bizPath);
            //update-begin-author:lvdandan date:20200928 for:修改JEditor编辑器本地上传
            /**  富文本编辑器及markdown本地上传时，采用返回链接方式
             //针对jeditor编辑器如何使 lcaol模式，采用 base64格式存储
             String jeditor = request.getParameter("jeditor");
             if(oConvertUtils.isNotEmpty(jeditor)){
             result.setMessage(CommonConstant.UPLOAD_TYPE_LOCAL);
             result.setSuccess(true);
             return result;
             }else{
             savePath = this.uploadLocal(file,bizPath);
             }
             */
        }else{
            //update-begin-author:taoyan date:20200814 for:文件上传改造
            savePath = CommonUtils.upload(file, bizPath, uploadType);
            //update-end-author:taoyan date:20200814 for:文件上传改造
        }
        if(oConvertUtils.isNotEmpty(savePath)){
            result.setMessage(savePath);
            result.setSuccess(true);
        }else {
            result.setMessage("上传失败！");
            result.setSuccess(false);
        }
        return result;
    }

    /**
     * 本地文件上传
     * @param mf 文件
     * @param bizPath  自定义路径
     * @return
     */
    private String uploadLocal(MultipartFile mf,String bizPath){
        try {
            String ctxPath = uploadpath;
            String fileName = null;
            File file = new File(ctxPath + File.separator + bizPath + File.separator );
            if (!file.exists()) {
                file.mkdirs();// 创建文件根目录
            }
            String orgName = mf.getOriginalFilename();// 获取文件名
            orgName = CommonUtils.getFileName(orgName);
            if(orgName.indexOf(".")!=-1){
                fileName = orgName.substring(0, orgName.lastIndexOf(".")) + "_" + System.currentTimeMillis() + orgName.substring(orgName.indexOf("."));
            }else{
                fileName = orgName+ "_" + System.currentTimeMillis();
            }
            String savePath = file.getPath() + File.separator + fileName;
            File savefile = new File(savePath);
            FileCopyUtils.copy(mf.getBytes(), savefile);
            String dbpath = null;
            if(oConvertUtils.isNotEmpty(bizPath)){
                dbpath = bizPath + File.separator + fileName;
            }else{
                dbpath = fileName;
            }
            if (dbpath.contains("\\")) {
                dbpath = dbpath.replace("\\", "/");
            }
            return dbpath;
        } catch (IOException e) {
            log.error(e.getMessage(), e);
        }
        return "";
    }

    @PostMapping(value = "/uploadFile")
    public Result<?> uploadFile(HttpServletRequest request, HttpServletResponse response) {
        Result<?> result = new Result<>();
        try {
            String ctxPath = uploadpath;
            String fileName = null;
            String bizPath = "files";
            String nowday = new SimpleDateFormat("yyyyMMdd").format(new Date());
            File file = new File(ctxPath + File.separator + bizPath + File.separator + nowday);
            if (!file.exists()) {
                file.mkdirs();// 创建文件根目录
            }
            MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
            MultipartFile mf = multipartRequest.getFile("file");// 获取上传文件对象
            String orgName = mf.getOriginalFilename();// 获取文件名
            fileName = orgName.substring(0, orgName.lastIndexOf(".")) + "_" + System.currentTimeMillis() + orgName.substring(orgName.indexOf("."));
            String savePath = file.getPath() + File.separator + fileName;
            File savefile = new File(savePath);
            FileCopyUtils.copy(mf.getBytes(), savefile);
            String dbpath = bizPath + File.separator + nowday + File.separator + fileName;
            if (dbpath.contains("\\")) {
                dbpath = dbpath.replace("\\", "/");
            }
            result.setMessage(dbpath);
            result.setSuccess(true);
        } catch (IOException e) {
            result.setSuccess(false);
            result.setMessage(e.getMessage());
            log.error(e.getMessage(), e);
        }
        return result;
    }

    /**
     * 小程序
     *
     * @param technologyNews
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    @AutoLog(value = "科技咨询-分页列表查询")
    @ApiOperation(value="科技咨询-分页列表查询", notes="科技咨询-分页列表查询")
    @GetMapping(value = "/min/list")
    public Result<?> queryPageMinList(TechnologyNews technologyNews,
                                      @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                      @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                                      HttpServletRequest req) {
        QueryWrapper<TechnologyNews> queryWrapper = QueryGenerator.initQueryWrapper(technologyNews, req.getParameterMap());
        Page<TechnologyNews> page = new Page<TechnologyNews>(pageNo, pageSize);
        IPage<TechnologyNews> pageList = technologyNewsService.page(page, queryWrapper);
        return Result.OK(pageList);
    }

    /**
     * 小程序-我的科技交流-分页列表查询
     *
     * @param pageNo
     * @param unionId
     * @param status
     * @return
     */
    @AutoLog(value = "小程序-我的科技交流-分页列表查询")
    @ApiOperation(value="小程序-我的科技交流-分页列表查询", notes="小程序-我的科技交流-分页列表查询")
    @GetMapping(value = "/technologyList")
    public MiniResult<List<Map<String, Object>>> technologyList(
            @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
            @RequestParam(name="unionId",required=true) String unionId,
            @RequestParam(name="status",required=true) Integer status

    ) throws Exception {
        MiniResult<List<Map<String, Object>>> result = new MiniResult<List<Map<String, Object>>>();

        QueryWrapper<TechnologyNews> queryWrapper = new QueryWrapper<TechnologyNews>();
        queryWrapper.eq("union_id", unionId);
        if (status!=-2){
            queryWrapper.eq("status", status);
        }

        Page<TechnologyNews> page = new Page<TechnologyNews>(pageNo, 10);
        IPage<TechnologyNews> pageList = technologyNewsService.page(page, queryWrapper);
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        if (pageList.getSize() > 0) {
            for (int i = 0; i < pageList.getRecords().size(); i++) {
                TechnologyNews entity = pageList.getRecords().get(i);
                Map<String, Object> map = new HashMap<String, Object>();
                map.put("id", entity.getId());
                map.put("title", entity.getTitle());
                map.put("author", entity.getAuthor());
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
                String createTime = simpleDateFormat.format(entity.getCreateTime());
                map.put("createTime", createTime);
                String imgUrl = SecurityUtil.GetFullUrl(entity.getImgUrl(),fullUrl);
                map.put("imgUrl", imgUrl);

                list.add(map);
            }
        }
        result.setCount(list.size());
        result.setData(list);
        return result;
    }

    /**
     *   小程序-我的科技交流-通过id删除
     *
     * @param id
     * @return
     */
    @AutoLog(value = "小程序-我的科技交流-通过id删除")
    @ApiOperation(value="小程序-我的科技交流-通过id删除", notes="小程序-我的科技交流-通过id删除")
    @GetMapping(value = "/deleteTechnology")
    public MiniResult<?> deleteTechnology(@RequestParam(name="id",required=true) String id) {
        MiniResult result = new MiniResult();
        // 只删除主表？
        technologyNewsService.removeById(id);

        result.setCount(1);
        result.setMsg("删除成功");
        return result;
    }

    /**
     * 小程序-我的资讯-分页列表查询
     *
     * @param pageNo
     * @param unionId
     * @param status
     * @return
     */
    @AutoLog(value = "小程序-我的资讯-分页列表查询")
    @ApiOperation(value="小程序-我的资讯-分页列表查询", notes="小程序-我的资讯-分页列表查询")
    @GetMapping(value = "/myNewList")
    public MiniResult<List<Map<String, Object>>> myNewList(
            @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
            @RequestParam(name="unionId",required=true) String unionId,
            @RequestParam(name="status",required=true) Integer status

    ) throws Exception {
        MiniResult<List<Map<String, Object>>> result = new MiniResult<List<Map<String, Object>>>();

        QueryWrapper<News> queryWrapper = new QueryWrapper<News>();
        queryWrapper.eq("union_id", unionId);
        if (status!=-2){
            queryWrapper.eq("status", status);
        }

        Page<News> page = new Page<News>(pageNo, 10);
        IPage<News> pageList = newsService.page(page, queryWrapper);
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        if (pageList.getSize() > 0) {
            for (int i = 0; i < pageList.getRecords().size(); i++) {
                News entity = pageList.getRecords().get(i);
                Map<String, Object> map = new HashMap<String, Object>();
                map.put("id", entity.getId());
                map.put("title", entity.getTitle());
                map.put("author", entity.getAuthor());
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
                String createTime = simpleDateFormat.format(entity.getCreateTime());
                map.put("createTime", createTime);
                String imgUrl = SecurityUtil.GetFullUrl(entity.getImgUrl(),fullUrl);
                map.put("imgUrl", imgUrl);

                list.add(map);
            }
        }
        result.setCount(list.size());
        result.setData(list);
        return result;
    }

    /**
     *   小程序-我的资讯-通过id删除
     *
     * @param id
     * @return
     */
    @AutoLog(value = "小程序-我的资讯-通过id删除")
    @ApiOperation(value="小程序-我的资讯-通过id删除", notes="小程序-我的资讯-通过id删除")
    @GetMapping(value = "/deleteNew")
    public MiniResult<?> deleteNew(@RequestParam(name="id",required=true) String id) {
        MiniResult result = new MiniResult();
        // 只删除主表？
        newsService.removeById(id);

        result.setCount(1);
        result.setMsg("删除成功");
        return result;
    }

    /**
     * 小程序-我的供求-分页列表查询
     *
     * @param pageNo
     * @param unionId
     * @param status
     * @return
     */
    @AutoLog(value = "小程序-我的供求-分页列表查询")
    @ApiOperation(value="小程序-我的供求-分页列表查询", notes="小程序-我的供求-分页列表查询")
    @GetMapping(value = "/mySupplyList")
    public MiniResult<List<Map<String, Object>>> mySupplyList(
            @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
            @RequestParam(name="unionId",required=true) String unionId,
            @RequestParam(name="status",required=true) Integer status,
            @RequestParam(name="type",required=true) Integer type
    ) throws Exception {
        MiniResult<List<Map<String, Object>>> result = new MiniResult<List<Map<String, Object>>>();

        QueryWrapper<FaProduct> queryWrapper = new QueryWrapper<FaProduct>();
        queryWrapper.eq("union_id", unionId);
        if (type!=-2) {
            queryWrapper.eq("sd_type", type);
        }
        if (status!=-2){
            queryWrapper.eq("status", status);
        }

        Page<FaProduct> page = new Page<FaProduct>(pageNo, 10);
        IPage<FaProduct> pageList = faProductService.page(page, queryWrapper);
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        if (pageList.getSize() > 0) {
            for (int i = 0; i < pageList.getRecords().size(); i++) {
                FaProduct entity = pageList.getRecords().get(i);
                Map<String, Object> map = new HashMap<String, Object>();
                map.put("id", entity.getId());
                map.put("title", entity.getTitle());
                map.put("author", entity.getUnionName());
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
                String createTime = simpleDateFormat.format(entity.getCreateTime());
                map.put("addTime", createTime);
                map.put("createTime", createTime);
                String headImgUrl = SecurityUtil.GetFullUrl(entity.getHeadImgUrl(),fullUrl);
                map.put("headImgUrl", headImgUrl);
                String imgs = SecurityUtil.GetFullUrl(entity.getImgs(),fullUrl);
                map.put("imgs", imgs);
                map.put("imgUrl", imgs);
                map.put("sdType", entity.getSdType());
                map.put("sdCateName", "供应");
                String strStatus = "已完成";
                if (entity.getStatus() == 0){
                    strStatus = "进行中";
                }
                else if (entity.getStatus() == 1){
                    strStatus = "申请中";
                }
                else if (entity.getStatus() == 2){
                    strStatus = "未通过";
                }
                map.put("status", entity.getStatus());
                map.put("strStatus", strStatus);
                map.put("unionName", entity.getUnionName());
                map.put("nickName", entity.getUnionName());
                map.put("lmCount", entity.getLmCount());
                map.put("praiseCount", entity.getPraiseCount());
                map.put("remark", entity.getRemark());
                list.add(map);
            }
        }
        result.setCount(list.size());
        result.setData(list);
        return result;
    }

    /**
     *   小程序-供求产品表-通过id删除
     *
     * @param id
     * @return
     */
    @AutoLog(value = "小程序-供求产品表-通过id删除")
    @ApiOperation(value="小程序-供求产品表-通过id删除", notes="小程序-供求产品表-通过id删除")
    @GetMapping(value = "/deleteSdInfo")
    public MiniResult<?> deleteSdInfo(@RequestParam(name="id",required=true) String id) {
        MiniResult result = new MiniResult();
        // 只删除主表？
        faProductService.removeById(id);

        result.setCount(1);
        result.setMsg("删除成功");
        return result;
    }

    /**
     *   小程序-供求产品表-通过id更新状态为已完成
     *
     * @param id
     * @return
     */
    @AutoLog(value = "小程序-供求产品表-通过id更新状态为已完成")
    @ApiOperation(value="小程序-供求产品表-通过id更新状态为已完成", notes="小程序-供求产品表-通过id更新状态为已完成")
    @GetMapping(value = "/finishedSd")
    public MiniResult<?> finishedSd(@RequestParam(name="id",required=true) String id) {
        MiniResult result = new MiniResult();

        FaProduct p = faProductService.getById(id);
        p.setStatus(3); // 更新状态为已完成
        faProductService.updateById(p);

        result.setCount(1);
        result.setMsg("操作成功");
        return result;
    }


    /**
     * 小程序 - 我的收藏
     * @return
     */
    @AutoLog(value = "小程序 - 我的收藏")
    @ApiOperation(value="小程序 - 我的收藏", notes="小程序 - 我的收藏")
    @GetMapping(value = "/myCollection")
    public MiniResult<List<Map<String, Object>>> myCollection(@RequestParam(name="unionId",required=true) String unionId,
                                                              @RequestParam(name="pageNo", defaultValue="1") Integer pageNo
    ) throws Exception {
        MiniResult<List<Map<String, Object>>> result = new MiniResult<List<Map<String, Object>>>();
        Page<Map<String, Object>> page = new Page<Map<String, Object>>(pageNo, 10);
        List<Map<String, Object>> list = sysUserService.getMyCollection(page, unionId);
        for (int j = 0; j < list.size(); j++) {
            Map<String, Object> map = list.get(j);
            for (Map.Entry<String, Object> entry : map.entrySet()) {
                String key = entry.getKey();
                if (key.equals("imgUrl")){
                    if (entry.getValue() != null) {
                        String url = SecurityUtil.GetFullUrl(oConvertUtils.getString(entry.getValue()), fullUrl);
                        entry.setValue(url);
                    }
                }
            }
        }

        result.setCount(list.size());
        result.setData(list);
        return result;
    }

    /**
     *   小程序-我的收藏-新增
     *
     * @param unionId
     * @param collectedUnionId
     * @return
     */
    @AutoLog(value = "小程序-我的收藏-新增")
    @ApiOperation(value="小程序-我的收藏-新增", notes="小程序-我的收藏-新增")
    @GetMapping(value = "/addMyCollection")
    public MiniResult<?> addMyCollection(@RequestParam(name="unionId",required=true) String unionId,
                                            @RequestParam(name="collectedUnionId",required=true) String collectedUnionId) {
        MiniResult result = new MiniResult();
        sysUserService.addMyCollection(unionId,collectedUnionId);

        result.setCount(1);
        result.setMsg("收藏成功");
        return result;
    }

    /**
     *   小程序-我的收藏-通过unionId和collectedUnionId删除
     *
     * @param unionId
     * @param collectedUnionId
     * @return
     */
    @AutoLog(value = "小程序-我的收藏-通过unionId和collectedUnionId删除")
    @ApiOperation(value="小程序-我的收藏-通过unionId和collectedUnionId删除", notes="小程序-我的收藏-通过unionId和collectedUnionId删除")
    @GetMapping(value = "/deleteMyCollection")
    public MiniResult<?> deleteMyCollection(@RequestParam(name="unionId",required=true) String unionId,
                                            @RequestParam(name="collectedUnionId",required=true) String collectedUnionId) {
        MiniResult result = new MiniResult();
        sysUserService.deleteMyCollection(unionId,collectedUnionId);

        result.setCount(1);
        result.setMsg("删除成功");
        return result;
    }

    /**
     * 小程序-我的科技交流-通过id查询
     *
     * @param technologyId
     * @return
     */
    @AutoLog(value = "小程序-科技交流信息-通过id查询")
    @ApiOperation(value="小程序-科技交流信息-通过id查询", notes="小程序-科技交流信息-通过id查询")
    @GetMapping(value = "/technologyDetail")
    public MiniResult technologyDetail(@RequestParam(name="technologyId",required=true) String technologyId
    ) throws Exception {
        TechnologyNews technologyNews = technologyNewsService.getById(technologyId);
        if(technologyNews==null) {
            return MiniResult.error("未找到对应数据");
        }
        String url = SecurityUtil.GetFullUrl(oConvertUtils.getString(technologyNews.getImgUrl()), fullUrl);
        technologyNews.setImgUrl(url);
        return MiniResult.OK(technologyNews);
    }

    @AutoLog(value = "小程序-资讯信息-通过id查询")
    @ApiOperation(value="小程序-资讯信息-通过id查询", notes="小程序-资讯信息-通过id查询")
    @GetMapping(value = "/newDetail")
    public MiniResult newDetail(@RequestParam(name="newsId",required=true) String newsId
    ) throws Exception {
        News entity = newsService.getById(newsId);
        if(entity==null) {
            return MiniResult.error("未找到对应数据");
        }
        String url = SecurityUtil.GetFullUrl(oConvertUtils.getString(entity.getImgUrl()), fullUrl);
        entity.setImgUrl(url);
        return MiniResult.OK(entity);
    }

    @AutoLog(value = "小程序-供应/供求信息-通过id查询")
    @ApiOperation(value="小程序-供应/供求信息-通过id查询", notes="小程序-供应/供求信息-通过id查询")
    @GetMapping(value = "/supplyDetail")
    public MiniResult supplyDetail(@RequestParam(name="sdId",required=true) String sdId
    ) throws Exception {
        FaProduct entity = faProductService.getById(sdId);
        if(entity==null) {
            return MiniResult.error("未找到对应数据");
        }
        String imgs = SecurityUtil.GetFullUrl(oConvertUtils.getString(entity.getImgs()), fullUrl);
        entity.setImgs(imgs);

        String headImgUrl = SecurityUtil.GetFullUrl(oConvertUtils.getString(entity.getHeadImgUrl()), fullUrl);
        entity.setHeadImgUrl(headImgUrl);
        return MiniResult.OK(entity);
    }

    /**
     * 小程序-科技交流-分类
     *
     * @return
     */
    @AutoLog(value = "小程序-科技交流-分类")
    @ApiOperation(value="小程序-科技交流-分类", notes="小程序-科技交流-分类")
    @GetMapping(value = "/technologyCateAll")
    public MiniResult technologyCateAll() throws Exception {
        MiniResult result = new MiniResult();
        // 查询字典
        QueryWrapper<SysDictItem> queryDictItemWrapper = new QueryWrapper<SysDictItem>();
        queryDictItemWrapper.eq("dict_id","1337042644600020994");//字典：科技咨询
        List<SysDictItem> list = sysDictItemService.list(queryDictItemWrapper);
        List<Map<String, Object>> retList = new ArrayList<>();
        if (list.size() > 0) {
            for (int i = 0; i < list.size(); i++) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.put("id", list.get(i).getItemValue());
                map.put("cateName",  list.get(i).getItemText());

                retList.add(map);
            }
        }
        result.setCount(retList.size());
        result.setData(retList);
        return result;
    }

    @AutoLog(value = "小程序-我的消息")
    @ApiOperation(value="小程序-我的消息", notes="小程序-我的消息")
    @GetMapping(value = "/userListAllSession")
    public MiniResult userListAllSession(@RequestParam(name="unionId",required=true) String unionId) throws Exception {
        MiniResult result = new MiniResult();

        List<Map<String, Object>> retList = productCommentService.getMyMessage(unionId);
        result.setCount(retList.size());
        result.setData(retList);
        return result;
    }
}
